package activity.collection;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.laoxinwen.app.R;

import common.BaseActivity;


public class FavoriteActivity extends BaseActivity {
    FrgArticle frgArticle = new FrgArticle();
    FrgNews frgNews = new FrgNews();
    FrgTopic frgTopic = new FrgTopic();
    @id(R.id.tab_container)
    private ViewGroup tabContiner;
    @id(R.id.viewPager)
    private ViewPager viewPager;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tab_article:
                viewPager.setCurrentItem(1);
                break;
            case R.id.tab_news:
                viewPager.setCurrentItem(0);
                break;
            case R.id.tab_topic:
                viewPager.setCurrentItem(2);
                break;
            case R.id.bt_back:
                finish();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collection_topic_list);
        loadView();
        setModuleNewsList();
        tabContiner.getChildAt(0).setSelected(true);
    }


    private void setModuleNewsList() {
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public int getCount() {
                return 3;
            }

            @Override
            public Fragment getItem(int index) {
                switch (index) {
                    case 0:
                        return frgNews;
                    case 1:
                        return frgArticle;
                    default:
                        return frgTopic;
                }
            }

        };
        viewPager.setAdapter(adapter);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageScrollStateChanged(int state) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageSelected(int position) {
                for (int i = 0; i < 3; i++) {
                    tabContiner.getChildAt(i).setSelected(false);
                }
                View selectedChild = tabContiner.getChildAt(position);
                selectedChild.setSelected(true);
            }
        });
    }
}
